package com.nmf.site.biz.pay.wechat.service;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.alibaba.fastjson.JSON;
import com.nmf.site.biz.pay.enums.PayStatus;
import com.nmf.site.biz.pay.service.BizPayService;
import com.nmf.site.biz.pay.service.IpnService;
import com.nmf.site.biz.pay.wechat.entity.WechatPayNotify;

@Component
public class NotifyService {
	Logger log = LoggerFactory.getLogger(WechatJsWebPay.class);
	@Autowired
	BizPayService bizPayService;
	@Autowired
	IpnService ipnService;
	@Transactional
	public void notifyWechat(WechatPayNotify wechatPayNotify, String xmlParam) {
		log.info(JSON.toJSONString(wechatPayNotify));
//		bizPayService.paySuccess(wechatPayNotify.getOut_trade_no(),wechatPayNotify.getTransaction_id());
		ipnService.addIpnInfo(Double.valueOf(wechatPayNotify.getTotal_fee()), PayStatus.SUCCESS, wechatPayNotify.getOut_trade_no(), 
				wechatPayNotify.getTransaction_id(), xmlParam);
		
	}
	
	
	@Transactional
	public void notifyAli(String amount,String notifyId, String tradeStatus,String tradeNo, String outTradeNo, String jsonParm, String sourceReqStr) {
//		bizPayService.paySuccess(tradeNo,outTradeNo);
		Double damount = Double.parseDouble(amount)*100d;
		ipnService.addIpnInfo(damount, PayStatus.SUCCESS, tradeNo, outTradeNo, sourceReqStr);
	}
}
